package cn.bytecollege.user.filter;

import cn.bytecollege.common.entity.User;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "OrderDetailLoginFilter",servletNames = {"OrderDetailSaveController","OrderDetailNowbuyController","OrderDetailListController","OrdersSaveController","OrderDetailUpdateController","OederDetailDeleteController","UserInformationController","AddressListFindController"})
public class OrderDetailLoginFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request=(HttpServletRequest) req;
        HttpSession session= request.getSession();
        User user1=(User) session.getAttribute("user");
        String msg=null;
        if(user1==null){
            msg="还未登录请先登录";
            request.getRequestDispatcher("/user/userLogin.jsp").forward(request,resp);
            return;
        }

        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
